
#foreach ($diagram in $Diagram)
#set($eList = $report.getDiagramElements($diagram))
update test.document_template set permissions = '#foreach ($role in $eList)
#if($report.containsStereotype($role, "secuml.role")) 
#foreach ($form in $eList)
#if($report.containsStereotype($form, "secuml.resource")) 
#foreach($attributes in $form.ownedAttribute)
#if($attributes.name == "ID")
#set($formId = $attributes.defaultValue)
#end##if
#set($attributeClass="")
#foreach ($formClass in $eList)
#if($report.containsStereotype($formClass, "secuml.resource"))
#if($attributes.type.name == $formClass.name)
#set($attributeClass = $attributes.type.name)
#end##if
#end##if
#end##foreach
#if($attributeClass!="") 
#set($fieldName = $attributeClass)
#end##if
#if($attributeClass=="")
#set($fieldName = $attributes.name)
#end##if
#set($hasRead = "-")
#set($hasWrite = "-")
#set($hasInsert = "-")
#set($hasDelete= "-")
#foreach($roleAssociationClass in $AssociationClass)
#if($report.containsStereotype($roleAssociationClass, "secuml.permission"))
#if($roleAssociationClass.relatedElement.get(1).name == $role.name || $roleAssociationClass.relatedElement.get(0).name == $role.name) 
#foreach($associationProp in $roleAssociationClass.ownedAttribute)
#foreach($roleRight in $report.getRelationship($associationProp))
#if($attributes.name==$roleRight.target.get(0).name)
#if($associationProp.type.name == "read") 
#set($hasRead="R")
#end##if
#if($associationProp.type.name == "write") 
#set($hasWrite="W")
#end##if
#if($associationProp.type.name == "insert") 
#set($hasInsert="I")
#end##if
#if($associationProp.type.name == "delete") 
#set($hasDelete="D")
#end##if
#end##if
#end##foreach
#end##foreach
#end##if
#end##if
#end##foreach
#if($fieldName != "" && $fieldName != "ID")$role.name<>$fieldName>>$hasRead,$hasWrite,$hasInsert,$hasDelete<break>#end##if
#end##foreach
#end##if
#end##forearch 
#end##if
#end##foreach
' 
where id=$formId.value;
#end##foreach
